$().ready(function() {
	validateRule();
    // 适用等级带回渲染选中状态
	var grade = $("#grade").val();
   var gradeList = grade.split(",");
   $("input[name='grade']").each(function () {
       for(var i=0;i<gradeList.length;i++){
           if($(this).val()==gradeList[i]){
               $(this).attr("checked",true)
           }
       }
   })
});

$.validator.setDefaults({
	submitHandler : function() {
		update();
	}
});
function update() {
	$.ajax({
		cache : true,
		type : "POST",
		url : "/jzweb/knowledgePoints/update",
		data : $('#signupForm').serialize(),// 你的formid
		async : false,
		error : function(request) {
			parent.layer.alert("Connection error");
		},
		success : function(data) {
			if (data.code == 0) {
				parent.layer.msg("操作成功");
				parent.reLoad();
				var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
				parent.layer.close(index);

			} else {
				parent.layer.alert(data.msg)
			}

		}
	});

}
function validateRule() {
	var icon = "<i class='fa fa-times-circle'></i> ";
    $("#signupForm").validate({
        rules : {
            name : {
                required : true
            },
            newsId : {
                required : true
            }
        },
        messages : {
            name : {
                required : icon + "请输入知识点名称"
            },
            newsId : {
                required : icon + "请选择证书"
            }
        }
    })
}

var openDept = function(){
    layer.open({
        type:2,
        title:"上级菜单",
        area : [ '300px', '450px' ],
        content:"/jzweb/knowledgePoints/treeView"
    })
};
function loadDept(deptId,deptName,level){
	console.log("level",level);
    $("#pid").val(deptId);
    $("#pidName").val(deptName);
    $("#level").val(level*1+1);
}